Quantum Gates
<h1>Quantum Gates</h1>
<p>
<strong>Quantum gates</strong> are the fundamental building blocks of quantum circuits.
They manipulate the state of <strong>qubits</strong> in a quantum computer, similar to how
logic gates operate on bits in classical computers.
</p>
<p>
However, unlike classical gates that work with definite states (0 or 1), quantum gates
operate on <strong>probability amplitudes</strong> and can create superposition, entanglement,
and interference.
</p>
<img class="img-fluid" src="/static/images/bloch_sphere.png"
alt="Quantum Circuit" width="550">
<hr>
<h2>Classical Gates vs Quantum Gates</h2>
<table border="1" cellpadding="10">
<tr>
<th>Feature</th>
<th>Classical Gates</th>
<th>Quantum Gates</th>
</tr>
<tr>
<td>Unit</td>
<td>Bit</td>
<td>Qubit</td>
</tr>
<tr>
<td>Operation</td>
<td>Deterministic</td>
<td>Probability amplitudes</td>
</tr>
<tr>
<td>Examples</td>
<td>AND, OR, NOT</td>
<td>H, X, Z, CNOT</td>
</tr>
<tr>
<td>State Change</td>
<td>0 → 1</td>
<td>Quantum state transformation</td>
</tr>
</table>
<hr>
<h2>Types of Quantum Gates</h2>
<p>
Quantum circuits use several gates to manipulate qubits. The most important ones include:
</p>
<ul>
<li>Hadamard Gate (H)</li>
<li>Pauli-X Gate (X)</li>
<li>Pauli-Z Gate (Z)</li>
<li>Controlled-NOT Gate (CNOT)</li>
</ul>
<hr>
<h2>1. Hadamard Gate (H)</h2>
<p>
The <strong>Hadamard gate</strong> creates superposition. It transforms a definite state
into a combination of both states.
</p>
<pre>
|0⟩ → (|0⟩ + |1⟩) / √2
|1⟩ → (|0⟩ - |1⟩) / √2
</pre>
<p>
This gate is commonly used at the beginning of quantum algorithms to allow the
system to explore multiple possibilities simultaneously.
</p>
<hr>
<h2>2. Pauli-X Gate (X)</h2>
<p>
The <strong>Pauli-X gate</strong> works similar to a classical NOT gate.
It flips the state of a qubit.
</p>
<pre>
|0⟩ → |1⟩
|1⟩ → |0⟩
</pre>
<p>
This gate is often used to toggle or invert quantum states.
</p>
<hr>
<h2>3. Pauli-Z Gate (Z)</h2>
<p>
The <strong>Pauli-Z gate</strong> changes the phase of the qubit without affecting
its probability of being measured as 0 or 1.
</p>
<pre>
|0⟩ → |0⟩
|1⟩ → -|1⟩
</pre>
<p>
It is commonly used in quantum algorithms to manipulate phase information.
</p>
<hr>
<h2>4. Controlled-NOT Gate (CNOT)</h2>
<p>
The <strong>CNOT gate</strong> is a two-qubit gate used to create entanglement.
It flips the target qubit only if the control qubit is in state |1⟩.
</p>
<table border="1" cellpadding="10">
<tr>
<th>Control</th>
<th>Target</th>
<th>Result</th>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>00</td>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>01</td>
</tr>
<tr>
<td>1</td>
<td>0</td>
<td>11</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td>10</td>
</tr>
</table>
<p>
CNOT is essential for generating quantum entanglement between qubits.
</p>
<hr>
<h2>Example: Quantum Circuit using Qiskit</h2>
<p>
The following Python code demonstrates a simple quantum circuit using
Hadamard and CNOT gates.
</p>
<pre><code class="language-python">
from qiskit import QuantumCircuit
# Create circuit with 2 qubits
qc = QuantumCircuit(2)
# Create superposition
qc.h(0)
# Create entanglement
qc.cx(0,1)
# Measure qubits
qc.measure_all()
print(qc)
</code></pre>
<hr>
<h2>Why Quantum Gates Matter</h2>
<p>
Quantum gates are the foundation of quantum algorithms. By applying
different sequences of gates, quantum computers can perform complex
calculations much faster than classical computers.
</p>
<ul>
<li>Create superposition</li>
<li>Generate entanglement</li>
<li>Manipulate quantum phases</li>
<li>Build quantum algorithms</li>
</ul>
<hr>
<h2>Conclusion</h2>
<p>
Quantum gates are the building blocks of quantum computation. Gates such as
<strong>H, X, Z, and CNOT</strong> allow quantum computers to manipulate qubits
and perform powerful operations that enable algorithms like Shor's and Grover's.
</p>